package com.kfm.wiki.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kfm.wiki.entity.EbookSnapshot;
import com.kfm.wiki.entity.SnapshotResp;
import com.kfm.wiki.service.EbookSnapshotService;
import com.kfm.wiki.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ebook-snapshot")
public class EbookSnapshotController {

    @Autowired
    private EbookSnapshotService service;

    @GetMapping("/get")
    public R statistic (){
        return R.ok(service.statistic());
    }

    @GetMapping("/get30")
    public R statistic30 (){
        List<SnapshotResp> snapshotResps = service.statistic30();
        try {
            System.out.println(new ObjectMapper().writeValueAsString(snapshotResps));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return R.ok(snapshotResps);
    }
}
